﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Paragon;

namespace Paragon.Tests
{
    [TestClass]
    public class TestStringExtensions
    {
        [TestMethod]
        public void TestPara()
        {
            A a = new A()
            {
                Id = Guid.NewGuid(),
                Name = "Paragon Test",
                Description = "This is a test of the para function",
                Weight = 12.01m,
                Cost = 1203.10,
                Stamp = new DateTime(2011, 11, 11, 1, 12, 0),
                B = new B()
                {
                    Name = "Subclass",
                    Values = new List<string>()
                }
            };

            a.B.Values.Add("Place 1");
            a.B.Values.Add("Place 2");
            a.B.Values.Add("Place 3");

            string template = "This is ${p0:Name}";
            string result = template.Para(a);
            Assert.AreEqual<string>("This is Paragon Test", result);

            template = "This is a ${p0:Name}.  ${p0:Description}.  It's weight: ${p0:Weight:0.0}, and costs ${p0:Cost:c}.";
            result = template.Para(a);
            Assert.AreEqual<string>("This is a Paragon Test.  This is a test of the para function.  It's weight: 12.0, and costs $1,203.10.", result);

            template = "ID: {${p0:Id}} Has ${p1:Name} for ${p1:Values.Count} Values";
            result = template.Para(a, a.B);
            Assert.AreEqual<string>("ID: {" + a.Id + "} Has Subclass for 3 Values", result);

            template = "${e:ComputerName}";
            result = template.Para();
            Assert.AreEqual<string>(Environment.GetEnvironmentVariable("ComputerName"), result);
            Assert.IsTrue(result.Length > 0);

            template = "${p0}";
            result = template.Para(a);
            Assert.AreEqual<string>("Id: " + a.Id, result);

            template = "${p0:Stamp:M/d h:mm tt}";
            result = template.Para(a);
            Assert.AreEqual<string>("11/11 1:12 AM", result);
        }

        private class A
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
            public decimal Weight { get; set; }
            public double Cost { get; set; }
            public DateTime Stamp { get; set; }
            public B B { get; set; }

            public override string ToString()
            {
                return "Id: " + Id.ToString();
            }
        }

        private class B
        {
            public string Name { get; set; }
            public List<string> Values { get; set; }
        }
    }
}
